<?php

require_once 'classes/Charges.class.php';
require_once 'classes/Patients.class.php';
require_once 'classes/ChargeTypes.class.php';
require_once 'classes/ChargeCatagories.class.php';

$objCharges 		= new Charges();
$arrobjCharges 	= $objCharges->fetchAllCharges();
$objPatients 	        = new Patients();
$objChargeTypes 	    = new ChargeTypes();
$objChargeCatagories 	= new ChargeCatagories();

// display( $arrobjPatients ); exit;

if( false == valArr( $arrobjCharges ) ) {
	echo '<h2>Charges are not avaliable.</h2>';
} else {
?>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<script>
function DeleteData(id){
               var r = confirm("Are You Sure Delete This Charges?");
               if (r==true){
                  $.ajax({
                     type: "POST",
                     url: "modules.php?file=delete_charges",
                     data:{did:id},
                     beforeSend : function () {
                     },
                     success:function(){
					 location.reload();
                     }
                  });
               }else{   
               }
            }
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>

	<div style="margin-left:20px; margin-top: 10px;">
		<p>
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=charges&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Create New Charge</a>&nbsp;
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_charges&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Charges</a>
		</p>
	</div>
	
<div class="col-lg-12">
	<div class="panel panel-primary">
		
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Charges List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Patient Name</th>
							<th>Charge Type</th>
							<th>Charge Catagory</th>
							<th>Min Amount</th>
							<th>Max Amount</th>
							<th>Rate</th>
							<th>Edit</th>
							<th>Delete</th>
					</thead>
					<tbody class="tbclass">
					<?php 
					$intSnCount = 0;
					foreach( $arrobjCharges as $objCharge ) {
						$intSnCount++;
						$arrobjPatients 	= $objPatients->fetchPatientsById($objCharge->getPatientId());
						$arrobjChargeTypes 	= $objChargeTypes->fetchChargeTypesById($objCharge->getChargeTypeId());
						$arrobjChargeCatagories 	= $objChargeCatagories->fetchChargeCatagoriesById($objCharge->getChargeCatagoryId());
					?>
							<tr class="odd gradeX">
							<td><?  echo $intSnCount; ?></td>
							<td><? echo $arrobjPatients->getFirstName(); ?>&nbsp;<? echo $arrobjPatients->getLastName(); ?></td>
							<td><? echo $arrobjChargeTypes->getName(); ?></td>
							<td><? echo $arrobjChargeCatagories->getName(); ?></td>
							<td><? echo $objCharge->getMinAmount(); ?></td>
							<td><? echo $objCharge->getMaxAmount(); ?></td>
							<td><? echo $objCharge->getRate(); ?></td>
							<td>
								<a href="modules.php?file=charges&charge_id=<? echo $objCharge->getId(); ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>" title="Update patient information"><img src="images/icons/update.png" width="25" height="25"></a>
							</td>
							<td>
								<a  id="delete_charge" onClick="DeleteData(<?echo $objCharge->getId();?>);"><img src="images/icons/delete.jpg" width="25" height="25"></a>
							</td>
							</tr>
					<?
					} 
					?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<?php
}
?>